﻿using System;
using System.Linq;
using System.Runtime.Serialization;

namespace StreetPacMan.Server.Facade
{
    [DataContract]
    public class GetAllGamesResult
    {
        [DataMember]
        public ClientGame[] Games { get; private set; }

        public GetAllGamesResult(ClientGame[] games)
        {
            Games = games;
        }
    }

    [DataContract]
    public class ClientGame
    {
        public ClientGame(int id, string name, GameState state, GamePlayer[] players)
        {
            Id = id;
            Name = name;
            State = state;
            Players = players;
        }

        [DataMember]
        public int Id { get; private set; }

        [DataMember]
        public string Name { get; private set; }

        [DataMember]
        public GameState State { get; private set; }

        [DataMember]
        public GamePlayer[] Players { get; private set; }
    }

    [DataContract]
    public class GamePlayer
    {
        public GamePlayer(int entityId, string name, PlayerRole role, PlayerState state)
        {
            EntityId = entityId;
            Name = name;
            Role = role;
            State = state;
        }

        [DataMember]
        public int EntityId { get; private set; }

        [DataMember]
        public string Name { get; private set; }

        [DataMember]
        public PlayerRole Role { get; private set; }

        [DataMember]
        public PlayerState State { get; private set; }
    }

    [DataContract]
    public class GetAllEventsResults
    {
        public GetAllEventsResults(Event[] gameEvents)
        {
            Events = gameEvents.Select(x => new ClientEvent(x.ReceivedAt, x.Description, x.TypeEnum)).ToArray();
        }

        [DataMember]
        public ClientEvent[] Events { get; private set; }
    }

    [DataContract]
    public class ClientEvent
    {
        [DataMember]
        public DateTime ReceivedAt { get; private set; }
        [DataMember]
        public string Description { get; private set; }
        [DataMember]
        public EventType Type { get; private set; }

        public ClientEvent(DateTime receivedAt, string description, EventType type)
        {
            ReceivedAt = receivedAt;
            Description = description;
            Type = type;
        }
    }

    public class GetAllEventsParameters
    {
        public int GameId { get; private set; }

        public GetAllEventsParameters(int gameId)
        {
            GameId = gameId;
        }
    }
}